package org.sdp.pearproject.controller;


import org.sdp.pearproject.controller.custom.*;
import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: IndexController
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-25
 * @Version: 1.0
 * Table: index
 * Comment:
 * 
 */
@RestController
@RequestMapping(value = "/index")
public class IndexController extends IndexCustomController {
    static {
        addRequestClass("index", "add", "indexController", IndexController.class, IndexAddRequest.class);
        addRequestClass("index", "add_encrypt", "indexController", IndexController.class, IndexAddRequest.class);

        addRequestClass("index", "update", "indexController", IndexController.class, IndexUpdateRequest.class);
        addRequestClass("index", "update_encrypt", "indexController", IndexController.class, IndexUpdateRequest.class);

        addRequestClass("index", "delete", "indexController", IndexController.class, IndexDeleteRequest.class);
        addRequestClass("index", "delete_encrypt", "indexController", IndexController.class, IndexDeleteRequest.class);

        addRequestClass("index", "query", "indexController", IndexController.class, IndexQueryRequest.class);
        addRequestClass("index", "query_encrypt", "indexController", IndexController.class, IndexQueryRequest.class);

        addRequestClass("index", "list", "indexController", IndexController.class, IndexQueryRequest.class);
        addRequestClass("index", "list_encrypt", "indexController", IndexController.class, IndexQueryRequest.class);

        addRequestClass("index", "count", "indexController", IndexController.class, IndexQueryRequest.class);
        addRequestClass("index", "count_encrypt", "indexController", IndexController.class, IndexQueryRequest.class);

        addRequestClass("index", "stat", "indexController", IndexController.class, IndexQueryRequest.class);
        addRequestClass("index", "stat_encrypt", "indexController", IndexController.class, IndexQueryRequest.class);

    }

    @PostMapping("/add")
    public Integer addIndex(@MixRequestBody IndexAddRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("index", "add", request, callFromEncrypt);
        return super.addIndex(request);
    }

    @PostMapping("/add_encrypt")
    public String addIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexAddRequest request = (IndexAddRequest) super.decrypt("index", "add_encrypt", strRequest, IndexAddRequest.class);
        Integer result = addIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/update")
    public Integer updateIndex(@MixRequestBody IndexUpdateRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("index", "update", request, callFromEncrypt);
        return super.updateIndex(request);
    }

    @PostMapping("/update_encrypt")
    public String updateIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexUpdateRequest request = (IndexUpdateRequest) super.decrypt("index", "update_encrypt", strRequest, IndexUpdateRequest.class);
        Integer result = updateIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/delete")
    public Integer deleteIndex(@MixRequestBody IndexDeleteRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("index", "delete", request, callFromEncrypt);
        return super.deleteIndex(request);
    }

    @PostMapping("/delete_encrypt")
    public String deleteIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexDeleteRequest request = (IndexDeleteRequest) super.decrypt("index", "delete_encrypt", strRequest, IndexDeleteRequest.class);
        Integer result = deleteIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/query")
    public IndexQueryResponse queryIndex(@MixRequestBody IndexQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("index", "query", request, callFromEncrypt);
      return super.queryIndex(request);
    }

    @PostMapping("/query_encrypt")
    public String queryIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexQueryRequest request = (IndexQueryRequest) super.decrypt("index", "query_encrypt", strRequest, IndexQueryRequest.class);
        IndexQueryResponse result = queryIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/list")
    public List<IndexQueryResponse> listIndex(@MixRequestBody IndexQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("index", "list", request, callFromEncrypt);
        if (super.needTotal("index", "list", request)) {
            super.setTotal("index", "list", request, super.countIndex(request));
        }
        return super.listIndex(request);
    }

    @PostMapping("/list_encrypt")
    public String listIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexQueryRequest request = (IndexQueryRequest) super.decrypt("index", "list_encrypt", strRequest, IndexQueryRequest.class);
        List<IndexQueryResponse> result = listIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/count")
    public Integer countIndex(@MixRequestBody IndexQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("index", "count", request, callFromEncrypt);
      return super.countIndex(request);
    }


    @PostMapping("/count_encrypt")
    public String countIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexQueryRequest request = (IndexQueryRequest) super.decrypt("index", "count_encrypt", strRequest, IndexQueryRequest.class);
        Integer result = countIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/stat")
    public BaseStatResponse statIndex(@MixRequestBody IndexQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("index", "stat", request, callFromEncrypt);
        return super.statIndex(request);
    }

    @PostMapping("/stat_encrypt")
    public String statIndexEncrypt(@MixRequestBody String strRequest) throws Exception {
        IndexQueryRequest request = (IndexQueryRequest) super.decrypt("index", "stat_encrypt", strRequest, IndexQueryRequest.class);
        BaseStatResponse result = statIndex(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }


    static {
        addRequestClass("index", "index/checkInstall", "indexController", IndexController.class, BaseRequest.class);
        addRequestClass("index", "index/checkInstall_encrypt", "indexController", IndexController.class, BaseRequest.class);
    }
    
    @ResponseBody
    @PostMapping("/index/checkInstall")
    public List<Object> indexCheckInstall(@MixRequestBody BaseRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("index", "index_check_install", request, callFromEncrypt);
        return super.indexCheckInstall(request);
    }

    @ResponseBody
    @PostMapping("/index/checkInstall_encrypt")
    public String indexCheckInstallEncrypt(@MixRequestBody String strRequest) throws Exception {
        BaseRequest request = (BaseRequest)decrypt("index", "index_check_install_encrypt", strRequest, BaseRequest.class);
        List<Object> result = indexCheckInstall(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);
        
        return super.encrypt(request, response);
    }

}
